package utils;

import java.sql.*;

public class JDBCUtils {
    public static Connection getConnection() throws SQLException, ClassNotFoundException
    {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/mvc?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
        String username = "root";
        String password = "lyt958524377394";
        Connection conn = DriverManager.getConnection(url, username, password);
        return conn;
    }
    //释放数据库连接
    public static void release(ResultSet rs, PreparedStatement pstmt, Connection conn) throws SQLException {
        if (rs != null) {

            rs.close();
        }
        rs = null;
        release(pstmt, conn);
    }
    public static void release(PreparedStatement pstmt, Connection conn) throws SQLException {
        if (pstmt != null) {
            pstmt.close();
        }
        pstmt = null;
        if (conn != null) {
            conn.close();
        }
        conn = null;
    }
}

